// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store/store'
import axios from 'axios'
import VueAxios from 'vue-axios'
import {
  Button,
  Tabbar,
  TabbarItem,
  NavBar,
  NoticeBar,
  Panel,
  Row,
  Col,
  Field,
  Cell,
  CellGroup,
  Checkbox,
  CheckboxGroup,
  Card,
  SubmitBar,
  Dialog,
  RadioGroup,
  Radio,
} from 'vant'
Vue.use(Tabbar).use(TabbarItem).use(NavBar).use(Button).use(NoticeBar)
  .use(Panel).use(Row).use(Col).use(Field).use(Cell).use(CellGroup)
  .use(Checkbox).use(CheckboxGroup).use(Card).use(SubmitBar).use(VueAxios,axios).use(Dialog).use(RadioGroup).use(Radio);

Vue.config.productionTip = false;

router.beforeEach((to, from, next) => {
  if (to.matched.some(r => r.meta.requireAuth)) {
    if (store.state.token) {
      next()
    } else {
      next({
        path: '/user'
      })
    }
  } else {
    next()
  }
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: {App},
  template: '<App/>'
})
